﻿using TelerikMvcGridCustomBindingHelper.Util;

namespace TelerikMvcGridCustomBindingHelper.NHibernate.Util
{
    public static class Generator
    {
        public static Alias GetCriteriaAliasFor(string associationPath)
        {
            Contract.Expect(() => associationPath).IsNotNull().Meet(s => s.Contains("."));

            var prop = associationPath.Substring(associationPath.LastIndexOf('.') + 1);

            var tmp = associationPath.Remove(associationPath.LastIndexOf('.'));

            var alias = string.Concat("gen_", tmp).Replace(".", string.Empty);
            
            return new Alias(associationPath, alias, tmp, prop);
        }
    }

    public class Alias
    {
        public readonly string TheAlias;
        public readonly string AssociationPath;
        public readonly string SourceValue;
        public readonly string Property;

        public Alias(string sourceValue, string alias, string associationPath, string property)
        {
            SourceValue = sourceValue;
            TheAlias = alias;
            AssociationPath = associationPath;
            Property = property;
        }
    }
}